#include "proj/tl_common.h"
#ifndef WIN32
#include "proj/mcu/watchdog_i.h"
#endif 
#include "proj_lib/ble/ll/ll.h"
#include "proj_lib/ble/blt_config.h"
#include "mesh/user_config.h"
#include "mesh/app_health.h"
#include "mesh/app_heartbeat.h"
#include "proj_lib/sig_mesh/app_mesh.h"
#include "mesh/remote_prov.h"
#include "mesh/lighting_model.h"
#include "mesh/lighting_model_HSL.h"
#include "mesh/lighting_model_xyL.h"
#include "mesh/lighting_model_LC.h"
#include "mesh/scene.h"
#include "mesh/time_model.h"
#include "mesh/sensors_model.h"
#include "mesh/scheduler.h"
#include "mesh/mesh_ota.h"
#include "mesh/mesh_property.h"
#include "mesh/generic_model.h"
unsigned char par_buf[12] = { 0 };
unsigned char lhextab[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void lhexstr(char * data, u32 len)
{
    int i;
	for(i = 0; i < len; i ++)
	{
		par_buf[i*2] = lhextab[(data[i] >> 4)];
		par_buf[i*2 +1] = lhextab[(data[i]&0xf)];
	}	
}
//接收到Mesh数据
int mesh_cmd_at_data(u8 *par, int par_len, mesh_cb_fun_par_t *cb_par)
{
    lhexstr((char*)par,par_len);
    if(cb_par->op == 0x0282)//开关
	{
        if(par_buf[0]=='0' && par_buf[1]=='1' && par_buf[4]=='4' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='0') //麻烦打开儿童餐椅
        { 
            at_print("0xF3 0x02 0x03 0xFF 0xFF 0xFF 0xFF 0xFF 0x45 0x44 0x06 0x7C\r\n");
        }
        if(par_buf[0]=='0' && par_buf[1]=='0' && par_buf[4]=='4' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='0') //请帮我关闭儿童餐椅
        {
            at_print("0xF3 0x02 0x05 0xFF 0xFF 0xFF 0xFF 0xFF 0x45 0x44 0x06 0x7E\r\n");
        }
        //at_print("into1\r\n");
	}
    else if(cb_par->op == 0x00d1)
    {
        //char buf[64] = {0};
       // at_print(buf);
       // at_print_hexstr((char*)par,par_len);
        //at_print("\r\n");
        if(par_buf[2]=='3' && par_buf[3]=='4' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='1') //打开儿童餐椅的音乐功能
        {
           at_print("0xF3 0x02 0x03 0xFF 0xFF 0xFF 0x03 0xFF 0x45 0x44 0x05 0x80\r\n");
        }
        if (par_buf[2]=='3' && par_buf[3]=='4' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='0') //关闭儿童餐椅的音乐功能
        {
           at_print("0xF3 0x02 0x03 0xFF 0xFF 0xFF 0x04 0xFF 0x45 0x44 0x05 0x81\r\n");
        }
        if (par_buf[2]=='4' && par_buf[3]=='E' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='0') //儿童餐椅停止摇摆
        {
           at_print("0xF3 0x02 0x03 0xFF 0x00 0xFF 0xFF 0xFF 0x45 0x44 0x05 0x7D\r\n");
        }
        if(par_buf[2]=='8' && par_buf[3]=='C' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='1') //把儿童餐椅的档位调到一档
        {
           at_print("0xF3 0x02 0x03 0xFF 0x01 0xFF 0xFF 0xFF 0x45 0x44 0x05 0x7E\r\n");
        }
        if(par_buf[2]=='8' && par_buf[3]=='C' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='2') //把儿童餐椅的档位调到二档
        {
           at_print("0xF3 0x02 0x03 0xFF 0x02 0xFF 0xFF 0xFF 0x45 0x44 0x05 0x7F\r\n");
        }
        if(par_buf[2]=='8' && par_buf[3]=='C' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='3') //把儿童餐椅的档位调到三档
        {
           at_print("0xF3 0x02 0x03 0xFF 0x03 0xFF 0xFF 0xFF 0x45 0x44 0x05 0x80\r\n");
        }
        if(par_buf[2]=='0' && par_buf[3]=='B' && par_buf[4]=='F' && par_buf[5]=='0' &&  par_buf[6]=='8' && par_buf[7]=='C' && par_buf[8]=='0' && par_buf[9]=='1'&& par_buf[10]=='0' && par_buf[11]=='1') //关
        {
           at_print("waiting\r\n");
        }
        if(par_buf[2]=='0' && par_buf[3] =='B' && par_buf[4]=='F' && par_buf[5]=='0' &&  par_buf[6]=='8' && par_buf[7]=='C' && par_buf[8]=='0' && par_buf[9]=='1' && par_buf[10]=='F' && par_buf[11]=='F') //关
        {
            at_print("waiting\r\n");
        }
        if(par_buf[2]=='4' && par_buf[3]=='E' && par_buf[4]=='0' && par_buf[5]=='1' &&  par_buf[6]=='0' && par_buf[7]=='1') //关
        {
            at_print("waiting\r\n");//at_print("0xF3 0x02 0x03 0xFF 0x00  0xFF  0xFF  0xFF 0x45 0x44 0x05 0x7D\r\n");
        }
        //at_print("into2\r\n");
    }
    else
    {
        //at_print("into3\r\n");
    }
    return 0;
}